#include "bsp_tim.h"

/**
 * @brief         HAL_TIM_PeriodElapsedCallback 重写定时中断回调
 * @param[out]    htim      TIM_HandleTypeDef句柄
 * @retval        void
 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
 if(htim == &htim1)
 {
    BSP_TIM1_PeriodElapsedCallback();
 }
}

/**
 * @brief         BSP_TIM1_PeriodElapsedCallback 供app使用的定时中断回调
 * @param         void      
 * @retval        uint8_t   回调状态
 */
volatile uint8_t tim_elapse_flag = 0;
__weak uint8_t BSP_TIM1_PeriodElapsedCallback(void)
{
  tim_elapse_flag = 1;
  return 1;
}

void BSP_TIM_EnableElapsedCallback(void)
{
  HAL_TIM_Base_Start_IT(&htim1);
}

void BSP_PWM_Init(void)
{
  HAL_TIM_Base_Start(&htim8);
  HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_1);
  HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_2);
  HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_3);
}

void BSP_PWM_SetPalse(uint16_t palse)
{
  __HAL_TIM_SetCompare(&htim8, TIM_CHANNEL_1, palse);
  __HAL_TIM_SetCompare(&htim8, TIM_CHANNEL_2, palse);
  __HAL_TIM_SetCompare(&htim8, TIM_CHANNEL_3, palse);
}

void BSP_PWM_DeInit(void)
{
  HAL_TIM_PWM_Stop(&htim8, TIM_CHANNEL_1);
  HAL_TIM_PWM_Stop(&htim8, TIM_CHANNEL_2);
  HAL_TIM_PWM_Stop(&htim8, TIM_CHANNEL_3);
}
